/**
 * asyncRoutes (异步路由)
 * 需要根据用户角色动态加载的路由
 */

// --- 组件导入 --- 
const Layout = () => import('@/layout/index.vue');

// 仪表盘
const DashboardWorkbench = () => import('@/views/dashboard/workbench.vue');
const DashboardReport = () => import('@/views/dashboard/report.vue');

// 用户管理
const UserMgmt = () => import('@/views/user/user-mgmt.vue');
const RoleCfg = () => import('@/views/user/role-cfg.vue');
export const Personal = () => import('@/views/user/personal.vue');

// 原始基础设置模块组件 (导入路径已更新)
const OriginalCargoInfo = () => import('@/views/settings/cargo-info.vue');
const OriginalCargoCategoryMgmt = () => import('@/views/settings/cargo-category.vue');
const OriginalSupplierProfile = () => import('@/views/settings/supplier-profile.vue');
const OriginalCustomerProfile = () => import('@/views/settings/customer-profile.vue');
const OriginalLogistics = () => import('@/views/settings/logistics.vue');

// 新增/重构后的组件
// 请将原仓库管理页面移动到 'src/views/settings/WarehouseManagement.vue'
const WarehouseManagement = () => import('@/views/settings/WarehouseManagement.vue');
// 请确保 'src/views/settings/LocationManagement.vue' 文件已创建
const LocationManagement = () => import('@/views/settings/LocationManagement.vue');
// 请将原库存查询页面移动到 'src/views/inventory/InventoryQuery.vue'
const InventoryQuery = () => import('@/views/inventory/InventoryQuery.vue');
// 请将原库存盘点页面移动到 'src/views/inventory/InventoryCount.vue'
const InventoryCount = () => import('@/views/inventory/InventoryCount.vue');
// 请将原库存预警页面移动到 'src/views/inventory/InventoryAlerts.vue'
const InventoryAlerts = () => import('@/views/inventory/InventoryAlerts.vue');
// 请将原入库单列表页面移动到 'src/views/inbound/InboundOrderList.vue'
const InboundOrderList = () => import('@/views/inbound/InboundOrderList.vue');
// 请创建或移动收货操作页面到 'src/views/inbound/ReceivingOperation.vue'
const ReceivingOperation = () => import('@/views/inbound/ReceivingOperation.vue');
// 请创建或移动上架操作页面到 'src/views/inbound/PutawayOperation.vue'
const PutawayOperation = () => import('@/views/inbound/PutawayOperation.vue');
// 请将原出库单列表页面移动到 'src/views/outbound/OutboundOrderList.vue'
const OutboundOrderList = () => import('@/views/outbound/OutboundOrderList.vue');
// 请将原拣货页面移动到 'src/views/outbound/PickingOperation.vue'
const PickingOperation = () => import('@/views/outbound/PickingOperation.vue');
// 请创建或移动发货页面到 'src/views/outbound/ShippingOperation.vue'
const ShippingOperation = () => import('@/views/outbound/ShippingOperation.vue');
// 系统信息模块
const SystemLog = () => import('@/views/about/system-log.vue');
const SystemInfo = () => import('@/views/about/system-info.vue');

// --- 主路由数组 --- 

export const asyncRoutes = [
  // 1. 仪表盘
  {
    path: '/dashboard',
    component: Layout,
    name: 'Dashboard',
    meta: {
      title: '仪表盘',
      icon: 'dashboard',
      requiresAuth: true,
      roles: ['admin', 'employee']
    },
    children: [
      {
        path: 'workbench',
        name: 'Workbench',
        component: DashboardWorkbench,
        meta: {
          title: '工作台',
          icon: 'desktop',
          requiresAuth: true,
          roles: ['admin', 'employee']
        }
      },
      {
        path: 'report',
        name: 'Report',
        component: DashboardReport,
        meta: {
          title: '统计报表',
          icon: 'file',
          requiresAuth: true,
          roles: ['admin', 'employee']
        }
      }
    ]
  },

  // 2. 权限管理
  {
    path: '/user',
    component: Layout,
    name: 'User',
    meta: {
      title: '权限管理',
      icon: 'user-group',
      requiresAuth: true,
      roles: ['admin']
    },
    children: [
      {
        path: 'user-mgmt',
        name: 'UserMgmt',
        component: UserMgmt,
        meta: {
          title: '用户管理',
          icon: 'user',
          requiresAuth: true,
          roles: ['admin']
        }
      },
      {
        path: 'role-cfg',
        name: 'RoleCfg',
        component: RoleCfg,
        meta: {
          title: '角色管理',
          icon: 'team',
          requiresAuth: true,
          roles: ['admin']
        }
      }
    ]
  },

  // 3. 基础设置 (包含仓库和库位管理)
  {
    path: '/basic-settings',
    component: Layout,
    name: 'BasicSettings',
    meta: {
      title: '基础设置',
      icon: 'setting',
      requiresAuth: true,
      roles: ['admin']
    },
    children: [
      {
        path: 'cargo-info',
        name: 'CargoInfo',
        component: OriginalCargoInfo,
        meta: { title: '货物信息', icon: 'tag', requiresAuth: true, roles: ['admin'] }
      },
      {
        path: 'cargo-category',
        name: 'CargoCategoryMgmt',
        component: OriginalCargoCategoryMgmt,
        meta: { title: '货物分类', icon: 'menu', requiresAuth: true, roles: ['admin'] }
      },
      {
        path: 'supplier-profile',
        name: 'SupplierProfile',
        component: OriginalSupplierProfile,
        meta: { title: '供应商资料', icon: 'apartment', requiresAuth: true, roles: ['admin'] }
      },
      {
        path: 'customer-profile',
        name: 'CustomerProfile',
        component: OriginalCustomerProfile,
        meta: { title: '客户资料', icon: 'user-group', requiresAuth: true, roles: ['admin'] }
      },
      {
        path: 'logistics',
        name: 'Logistics',
        component: OriginalLogistics,
        meta: { title: '物流管理', icon: 'export', requiresAuth: true, roles: ['admin'] }
      },
      {
        path: 'warehouses',
        name: 'WarehouseManagement',
        component: WarehouseManagement,
        meta: { title: '仓库管理', icon: 'home', requiresAuth: true, roles: ['admin'] }
      },
      {
        path: 'locations',
        name: 'LocationManagement',
        component: LocationManagement,
        meta: { title: '库位管理', icon: 'environment', requiresAuth: true, roles: ['admin'] }
      }
    ]
  },

  // 4. 库存管理 (重构后)
  {
    path: '/inventory',
    component: Layout,
    name: 'Inventory',
    meta: {
      title: '库存管理',
      icon: 'database',
      requiresAuth: true,
      roles: ['admin', 'employee']
    },
    children: [
      {
        path: 'query',
        name: 'InventoryQuery',
        component: InventoryQuery,
        meta: { title: '库存查询', icon: 'search', requiresAuth: true, roles: ['admin', 'employee'] }
      },
      {
        path: 'alerts',
        name: 'InventoryAlerts',
        component: InventoryAlerts,
        meta: { title: '库存预警', icon: 'alert', requiresAuth: true, roles: ['admin', 'employee'] }
      },
      {
        path: 'count',
        name: 'InventoryCount',
        component: InventoryCount,
        meta: { title: '库存盘点', icon: 'ordered-list', requiresAuth: true, roles: ['admin', 'employee'] }
      }
    ]
  },

  // 5. 入库管理 (重构后)
  {
    path: '/inbound',
    component: Layout,
    name: 'Inbound',
    meta: {
      title: '入库管理',
      icon: 'import',
      requiresAuth: true,
      roles: ['admin', 'employee']
    },
    children: [
      {
        path: 'orders',
        name: 'InboundOrderList',
        component: InboundOrderList,
        meta: { title: '入库单列表', icon: 'file', requiresAuth: true, roles: ['admin', 'employee'] }
      },
      {
        path: 'receive/:id',
        name: 'ReceivingOperation',
        component: ReceivingOperation,
        meta: {
          title: '收货操作',
          icon: 'file',
          noCache: true,
          activeMenu: '/inbound/orders',
          requiresAuth: true,
          roles: ['admin', 'employee']
        },
        hidden: true
      },
      {
        path: 'putaway/:id',
        name: 'PutawayOperation',
        component: PutawayOperation,
        meta: {
          title: '上架操作',
          icon: 'file',
          noCache: true,
          activeMenu: '/inbound/orders',
          requiresAuth: true,
          roles: ['admin', 'employee']
        },
        hidden: true
      }
    ]
  },

  // 6. 出库管理 (重构后)
  {
    path: '/outbound',
    component: Layout,
    name: 'Outbound',
    meta: {
      title: '出库管理',
      icon: 'export',
      requiresAuth: true,
      roles: ['admin', 'employee']
    },
    children: [
      {
        path: 'orders',
        name: 'OutboundOrderList',
        component: OutboundOrderList,
        meta: { title: '出库单列表', icon: 'file', requiresAuth: true, roles: ['admin', 'employee'] }
      },
      {
        path: 'pick/:id',
        name: 'PickingOperation',
        component: PickingOperation,
        meta: {
          title: '拣货操作',
          icon: 'file',
          noCache: true,
          activeMenu: '/outbound/orders',
          requiresAuth: true,
          roles: ['admin', 'employee']
        },
        hidden: true
      },
      {
        path: 'shipping/:id',
        name: 'ShippingOperation',
        component: ShippingOperation,
        meta: {
          title: '发货操作',
          icon: 'file',
          noCache: true,
          activeMenu: '/outbound/orders',
          requiresAuth: true,
          roles: ['admin', 'employee']
        },
        hidden: true
      }
    ]
  },

  // 7. 关于系统 (保持不变)
  {
    path: '/about',
    component: Layout,
    name: 'About',
    meta: {
      title: '关于系统',
      icon: 'info-circle',
      requiresAuth: true,
      roles: ['admin', 'employee']
    },
    children: [
      {
        path: 'system-info',
        name: 'SystemInfo',
        component: SystemInfo,
        meta: { 
          title: '系统信息', 
          icon: 'file-text', 
          requiresAuth: true, 
          roles: ['admin', 'employee'],
        }
      },
      {
        path: 'system-log',
        name: 'SystemLog',
        component: SystemLog,
        meta: { 
          title: '系统日志', 
          icon: 'calendar', 
          requiresAuth: true, 
          roles: ['admin'] 
        }
      }
    ]
  },
  
  // --- 其他路由（如个人中心，通常隐藏） ---
  {
    path: '/personal',
    component: Layout,
    name: 'PersonalRoute',
    meta: {
      title: '个人中心',
      icon: 'idcard',
      hidden: true,
      hideInMenu: true,
      requiresAuth: true,
      roles: ['admin', 'employee'],
      isStandalone: true
    },
    children: [
      {
        path: '',
        name: 'PersonalInfo',
        component: Personal,
        meta: {
          title: '个人中心',
          icon: 'user',
          hidden: true,
          hideInMenu: true,
          requiresAuth: true,
          roles: ['admin', 'employee']
        }
      }
    ]
  },
];
